#include "task_test.h"
#include "app_main.h"

xTaskHandle xTask3Handle;

void task_print(void * pvParameters)
{
	char *pcTaskName;
	volatile unsigned long ul;
	static portTickType xLastWakeTime;
	
	pcTaskName = (char *)pvParameters;
	for(;;)
	{

		printf(pcTaskName);

		vTaskDelay(250);
		printf("ulIdelCycleCount = %d \n",ulIdelCycleCount);
	
	}
}
void task_print1(void * pvParameters)
{
	char *pcTaskName;
	volatile unsigned long ul;
	static portTickType xLastWakeTime;
	unsigned portBASE_TYPE uxPriority;
	
	pcTaskName = (char *)pvParameters;
	uxPriority = uxTaskPriorityGet(NULL);
	//xTaskCreate(task3_delete,"Task3",configMINIMAL_STACK_SIZE * 5,NULL,3,&xTask3Handle);
	for(;;)
	{
		
		printf("Task1 is running\n");

		xTaskCreate(task3_delete,"Task3",configMINIMAL_STACK_SIZE * 3,NULL,3,&xTask3Handle);

		
		printf("next \n \n \n");
		vTaskDelay(300);
		
//		vTaskPrioritySet(xTask2Handle,uxPriority+1);
//		vTaskDelay(250);
//	for(ul=0;ul<15000000;)
//	{
//		ul++;
//	}

	}
}
void task3_delete(void *pvParameters)
{


	printf("hello Task3! \n");
	vTaskDelete(xTask3Handle); 
	vTaskDelay(250);
}
void task_print2(void * pvParameters)
{
	char *pcTaskName;
	volatile unsigned long ul;
	static portTickType xLastWakeTime;
	unsigned portBASE_TYPE uxPriority;
	uxPriority = uxTaskPriorityGet(NULL);
	
	pcTaskName = (char *)pvParameters;
	for(;;)
	{

		printf(pcTaskName);

		

		printf("return to  \n \n");
		vTaskPrioritySet(NULL,(uxPriority -2 ));
	//	for(ul=0;ul<15000000;)
	//	{
	//		ul++;
	//	}

		
	//	vTaskDelay(250);
		

	}
}
void task_sender(void *pvParameters)
{
	long lValueToSend;
	portBASE_TYPE xStatus;

	lValueToSend = (long) pvParameters;

	for(;;)
	{

		xStatus = xQueueSend(num_queue,&lValueToSend,0);

		if(xStatus != pdPASS)
		{

			printf("Could not send to the queue. \r\n");
		}

	}

}
void task_reciverd(void *pvParameters)
{
	long lReceivedValue;
	portBASE_TYPE xStatus;

	for(;;)
	{
		
		

		xStatus = xQueueReceive(num_queue,&lReceivedValue,1000);
		if(xStatus == pdPASS)
		{
			printf("Received = %d \r\n",lReceivedValue);
		
		}
		else
		{

			printf("nothing receive from the queue");
		}
		if(uxQueueMessagesWaiting(num_queue) != 0)
		{
			printf("Queue should have been empty \r\n");
		}
	}

}
